package com.example.li.day9_27.mvp.Presenter;

import android.util.Log;
import android.widget.Toast;

import com.example.li.day9_27.MainActivity;
import com.example.li.day9_27.mvp.Model.IMainModel;
import com.example.li.day9_27.mvp.Model.MainModel;
import com.example.li.day9_27.mvp.View.IMainView;
import com.example.li.day9_27.pojo.RequestData;
import com.example.li.day9_27.pojo.User;

public class MainPresenter implements IMainPresenter {

    private static final String TAG = "MainActivity";
    private IMainModel model;
    private IMainView view;

    public MainPresenter(IMainView iMainView) {
        this.view = iMainView;
        this.model=new MainModel();
    }

    @Override
    public void login(String userName, String psw) {

        model.login(userName, psw, new IMainModel.OnLoadCallback() {
            @Override
            public void OnSucceed(RequestData<User> userRequestData) {
                String code = userRequestData.getCode();
                User data = userRequestData.getData();
                if ("9999".equals(code)) {
                    if (data != null) {
                        view.updateUserInfo(data);
                    }
                } else if ("1006".equals(code)) {
                    view.showErrorInfo(userRequestData.getMsg());
                }
            }

            @Override
            public void OnFalie(Throwable throwable) {

            }
        });
    }
}
